<?php
require_once '../sub/init.php';
require_once 'chkUadm.php';
if(!is_mobile())header("Location: ./?wwwzeaicn=crm");
$row = $db->ROW(__TBL_CRM_HN__,"username,path_s,truename,title,agenttitle","flag=1 AND id=".$session_uid,"name");
if ($row){
	$username = $row['username'];
	$truename = trimhtml(dataIO($row['truename'],'out',7));
	$aboutus  = dataIO($row['aboutus'],'out');
	$title    = trimhtml(dataIO($row['title'],'out'));
	$agenttitle= dataIO($row['agenttitle'],'out');
	$agenttitle=(empty($agenttitle))?'总管':$agenttitle;
	$unum     = $row['unum'];
	$bbsnum   = $row['bbsnum'];
	$path_s   = $row['path_s'];
	$path_s_url = (!empty($path_s))?UP.$path_s:RES.'photo_m'.$sex.'.png';
}else{
	zeaialert('{"title":"信息不存在","btnt":"我知道了","url":"-1"}');	
}
$nav='m_crm';?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $_ADM['admSiteName']; ?>《CRM》</title>
<?php echo HEADMETA; ?>
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<style>
body{background-color:#fff}
.top_btn{position:relative;}
.hid_top{height:210px;position:relative;overflow:hidden;z-index:-1;background-color:<?php echo $_ADM['color'];?>}
.hid_top:after{width:200%;height:170px;position:absolute;left:-50%;top:0;z-index:-2;content:'';border-radius:0 0 50% 50%;background-size:50%}
.hid_top:before{content:'';position:absolute;top:0;left:0;width:100%;height:170px;z-index:1;overflow:hidden;background-size:100%;background-image:url("/res/m/img/my_bg.png");}
.logo{position:absolute;top:20px;left:20px;width:90px;height:90px;border-radius:46px;border:#fff 2px solid;object-fit:cover;-webkit-object-fit:cover;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.hid{background-color:#fff;position:absolute;width:78px;line-height:22px;top:95px;left:26px;font-size:13px;border-radius:20px;color:#666;background-image:-webkit-linear-gradient(left,#ccc,#eee,#ccc);border:rgba(255,255,255,.5) 1px solid}

.hid_top .truename{position:absolute;top:30px;left:120px;text-align:left;color:#fff}
.hid_top .truename h3{font-size:18px;font-weight:bold;display:inline-block;vertical-align:middle;color;#000}
.hid_top .truename span{font-size:12px;display:inline-block;line-height:18px;padding:0 5px;border-radius:10px 10px 10px 0;border:#fff 1px solid;margin-left:5px;vertical-align:middle}
.hid_top .truename .title{font-weight:normal;font-size:13px;margin-top:10px;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
a.m_set{color:#fff;font-size:22px;position:absolute;right:20px;top:15px}
a.m_crm{text-align:right;padding-right:8px;color:#fff;font-size:13px;position:absolute;right:0px;top:64px;line-height:32px;width:55px;background-color:rgba(0,0,0,.2);border-radius:30px 0 0 30px;border:#fff 1px solid;border-right:0}

.m_box3{width:94%;margin:0 auto;margin-top:-70px;border-radius:10px;background-color:#fff;text-align:left;box-sizing:border-box;padding-bottom:30px;box-shadow:0 0 24px rgb(0 0 0 / 8%)}
.m_box3 h4{width:100%;font-size:15px;font-weight:bold;line-height:50px;padding:0 15px;display:block;position:relative;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.m_box3 ul{width:95%;margin:0 auto;display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;-webkit-justify-content:space-between;justify-content:space-between}
.m_box3 ul a{width:33%;padding:10px;height:40px;border-radius:2px;box-sizing:border-box;position:relative;text-align:center}
.m_box3 ul a i{position:absolute;left:10px;top:0;width:40px;height:40px;line-height:40px;border-radius:20px;font-size:20px;color:#fff;background-color:<?php echo $_ADM['color'];?>}
.m_box3 ul a h6,.m_box3 ul a b{position:absolute;left:58px;top:0;text-align:left}
.m_box3 ul a h6{color:#999;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.m_box3 ul a b{top:20px;font-weight:normal;font-size:16px;color:<?php echo $_ADM['color'];?>;font-family:Arial, Helvetica, sans-serif}

.m_box{width:94%;margin:15px auto 0 auto;border-radius:8px;background-color:#fff;text-align:left;box-sizing:border-box;box-shadow:0 0 24px rgb(0 0 0 / 8%)}
.m_box h4{width:100%;font-size:15px;font-weight:bold;line-height:50px;padding:0 15px;display:block;position:relative;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.m_box h4 .ico,.m_box3 h4 .ico{width:60px;text-align:right;font-size:12px;color:#bbb;float:right;font-weight:normal}
.m_box ul {width:100%;box-sizing:border-box} 
.m_box ul a{width:33%;padding:0 10px;background-color:#fff;border-radius:2px;float:left;box-sizing:border-box;position:relative;border-right:#efefef 1px solid;text-align:center;margin-bottom:15px}
.m_box ul.cols3 a:nth-child(3n){margin-right:0;width:34%;border-right:0}
.m_box ul.cols2 a{width:50%}
.m_box ul.cols4 a{width:25%}
.m_box ul.cols4 a:nth-child(4n){border-right:0}
.m_box ul a h6{color:#999;line-height:13px;display:inline-block;font-size:13px}
.m_box ul a b{line-height:24px;color:<?php echo $_ADM['color'];?>;font-size:16px;font-family:Arial, Helvetica, sans-serif;display:block;font-weight:normal}
.m_box ul a b.h{color:#f00}
.m_box ul a span{position:absolute;right:16px;top:45px;color:#f60;font-size:14px}
.shbox ul a b{line-height:24px;}
</style>
</head>
<body>
<?php localhost_auth();?>
<div class="top_btn">
    <a href="<?php echo HOST;?>/m/hongniang.php?hid=<?php echo $session_uid;?>"><img src="<?php echo $path_s_url;?>" class="logo"></a>
    <div class="hid">ID：<?php echo $session_uid;?></div>
    <a href="m_crm_set.php" class="ico m_set">&#xe614;</a>
    <?php if($session_kind=='adm'){?><a href="m_adm.php" class="m_crm ico">主后台</a><?php }?>
</div>
<div class="hid_top">
	<div class="truename ">
        <h3><?php echo $truename;?></h3>
        <span><?php echo $agenttitle;?></span>
        <div class="title ">角色：<?php echo $session_title;?></div>
        <div class="title ">帐号：<?php echo $username;?></div>
    </div>
</div>
<?php
$SQL  = " kind<>4 AND (flag=1 OR flag=-2) AND admid>0 ";
$SQL .= getAgentSQL();

$SQL2  = " U.kind<>4 AND (U.flag=1 OR U.flag=-2) ";// AND U.admid>0
$SQL2 .= getAgentSQL('U');

//非主管默认显示自己客户
if(!CRM_ADM && !strstr($session_crmkind,'adm'))$SQLMY = " AND (admid=".$session_uid." OR hnid=".$session_uid." OR hnid2=".$session_uid.")";
if(!CRM_ADM && !strstr($session_crmkind,'adm'))$SQLMY2 = " AND (U.admid=".$session_uid." OR U.hnid=".$session_uid." OR U.hnid2=".$session_uid.")";
?>
<div class="m_box3">
    <h4>客户统计<a href="m_crm_user.php" class="ico">&#xe601;</a></h4>
    <ul>
        <a href="m_crm_user.php"><i class="ico">&#xe617;</i><h6>总数</h6><b><?php echo $db->COUNT(__TBL_USER__,$SQL.$SQLMY);?></b></a>
        <?php //if (strstr($session_crmkind,'adm') || CRM_ADM || strstr($session_crmkind,'sq')){?>
            <a href="m_crm_user.php?t=sq"><i class="ico">&#xe784;</i><h6>售前</h6><b><?php echo $db->COUNT(__TBL_USER__,$SQL.$SQLMY." AND crm_ugrade=0 ");?></b></a>
		<?php //}?>
        <?php //if (strstr($session_crmkind,'adm') || CRM_ADM || strstr($session_crmkind,'sh')){?>
        	<a href="m_crm_user.php?t=sh"><i class="ico">&#xe613;</i><h6>售后</h6><b><?php echo $db->COUNT(__TBL_USER__,$SQL.$SQLMY." AND crm_ugrade>0 ");?></b></a>
        <?php //}?>
    </ul>
    <div class="clear"></div>
</div>

<div class="clear"></div>
<div class="m_box">
    <h4>公海资源<a href="m_crm_user.php?ifgh=1" class="ico">&#xe601;</a></h4>
    <ul class="cols3">
        <a href="m_crm_user.php?ifgh=1"><h6>总数</h6><b><?php echo $db->COUNT(__TBL_USER__," kind<>4 AND (flag=1 OR flag=-2) AND admid=0 ".getAgentSQL('aloneArea'));?></b></a>
        <a href="m_crm_user.php?ifgh=1&s=ext&sex=1"><h6>男生</h6><b id="F2"><?php echo $db->COUNT(__TBL_USER__," kind<>4 AND (flag=1 OR flag=-2) AND admid=0 AND sex=1 ".getAgentSQL('aloneArea'));?></b></a>
        <a href="m_crm_user.php?ifgh=1&s=ext&sex=2"><h6>女生</h6><b id="F3"><?php echo $db->COUNT(__TBL_USER__," kind<>4 AND (flag=1 OR flag=-2) AND admid=0 AND sex=2 ".getAgentSQL('aloneArea'));?></b></a>
    </ul>
    <div class="clear"></div>
</div>

<div class="clear"></div>
<div class="m_box">
    <h4>跟进小计<a href="m_crm_user_bbs.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>" class="ico">&#xe601;</a></h4>
    <ul class="cols3">
		<?php
		//今天已跟进
		$today = YmdHis(ADDTIME,'Ymd');
		$rtt   = $db->query("SELECT COUNT(*) FROM ".__TBL_CRM_BBS__." B,".__TBL_USER__." U WHERE ".$SQL2.$SQLMY2." AND B.uid=U.id AND date_format(from_unixtime(B.addtime),'%Y-%m-%d') = '$today'");
		$roww  = $db->fetch_array($rtt);
		$sq_gj_num1 = $roww[0];
		//天需跟进
		$rtt  = $db->query("SELECT COUNT(*) FROM ".__TBL_CRM_BBS__." B,".__TBL_USER__." U WHERE ".$SQL2.$SQLMY2." AND B.uid=U.id AND date_format(from_unixtime(B.nexttime),'%Y-%m-%d') = '$today'");
		$roww = $db->fetch_array($rtt);
		$sq_gj_num2 = $roww[0];		
		
		//过期未跟进
		$rtt  = $db->query("SELECT COUNT(*) FROM ".__TBL_CRM_BBS__." B,".__TBL_USER__." U WHERE ".$SQL2.$SQLMY2." AND B.uid=U.id AND B.nexttime<".ADDTIME);
		$roww = $db->fetch_array($rtt);
		$sq_gj_num3 = $roww[0];		
		?>
        <a href="m_crm_user_bbs.php?addtime=4<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>今天已跟进</h6><b class="h">+<?php echo $sq_gj_num1;?></b></a>
        <a href="m_crm_user_bbs.php?nexttime=1<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>今天需跟进</h6><b id="F2"><?php echo $sq_gj_num2;?></b></a>
        <a href="m_crm_user_bbs.php?nexttime=4<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>过期未跟进</h6><b id="F3"><?php echo $sq_gj_num3;?></b></a>
    </ul>
    <div class="clear"></div>
</div>

<div class="m_box">
    <h4>客户牵线<a href="m_qianxian_list.php<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'?ifmy=1':'';?>" class="ico">&#xe601;</a></h4>
    <ul class="cols3">
		<?php
		if(!CRM_ADM)$SQL2 .= " AND B.admid=".$session_uid;
		//牵线进行中
		$rtt  = $db->query("SELECT COUNT(*) FROM ".__TBL_QIANXIAN__." B,".__TBL_USER__." U WHERE ".$SQL2." AND B.senduid=U.id AND B.flag=1 AND U.crm_flag<>3 ");
		$roww = $db->fetch_array($rtt);
		$qx_num1 = $roww[0];
		//牵线失败
		$rtt  = $db->query("SELECT COUNT(*) FROM ".__TBL_QIANXIAN__." B,".__TBL_USER__." U WHERE ".$SQL2." AND B.senduid=U.id AND B.flag=-1 AND U.crm_flag<>3 ");
		$roww = $db->fetch_array($rtt);
		$qx_num2 = $roww[0];
		//牵线成功
		$rtt  = $db->query("SELECT COUNT(*) FROM ".__TBL_QIANXIAN__." B,".__TBL_USER__." U WHERE ".$SQL2." AND B.senduid=U.id AND B.flag=2 AND U.crm_flag<>3 ");
		$roww = $db->fetch_array($rtt);
		$qx_num3 = $roww[0];
		?>  
        <a href="m_qianxian_list.php?qxflag=1<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>牵线进行中</h6><b><?php echo $qx_num1;?></b></a>
        <a href="m_qianxian_list.php?qxflag=-1<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>牵线失败</h6><b><?php echo $qx_num2;?></b></a>
        <a href="m_qianxian_list.php?qxflag=2<?php echo (!strstr($session_crmkind,'adm') && !CRM_ADM)?'&ifmy=1':'';?>"><h6>牵线成功</h6><b><?php echo $qx_num3;?></b></a>
    </ul>
    <div class="clear"></div>
</div>
<?php require_once 'm_crm_btm.php';?>